package idiet.wizards.page;

import idiet.Activator;
import idiet.bean.CustomerPal;
import idiet.bean.NurseTarget;
import idiet.service.CustomerPalService;
import idiet.service.NurseTargetService;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;

public class WizardPageCustomerNurseInfo extends WizardPage {
	private String name;
	private Text textName;
	private Combo comboPal;
	private Combo comboNurseTarget;
	private DateTime dateTimeBegin;
	private DateTime dateTimeForecastEnd;
	private Text textComment;
	private CustomerPalService palService=(CustomerPalService)Activator.getApplicationContext().getBean(CustomerPalService.class);
	private NurseTargetService nurseTargetService=(NurseTargetService)Activator.getApplicationContext().getBean("nurseTargetService");
	private Text textEffect;
	/**
	 * Create the wizard.
	 */
	public WizardPageCustomerNurseInfo() {
		super("wizardPage");
		setTitle("\u7B2C\u4E09\u6B65\uFF1A\u6DFB\u52A0\u5BA2\u6237\u8C03\u7406\u76EE\u6807\u4FE1\u606F");
		setDescription("\u6DFB\u52A0\u5BA2\u6237\u7684\u4F53\u529B\u6D3B\u52A8\u6C34\u5E73\u3001\u8C03\u7406\u76EE\u6807\u3001\u8C03\u7406\u8D77\u6B62\u65F6\u95F4\u7B49\u4FE1\u606F");
		//this.setPageComplete(false);
	}
	/*private void intialErrors(){
		this.errors.put("begin", "请选择调理开始时间");
	}*/
	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	@Override
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		GridLayout gl_container = new GridLayout(2, false);
		gl_container.marginRight = 100;
		gl_container.marginLeft = 60;
		container.setLayout(gl_container);
		
		Label label = new Label(container, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText("\u59D3\u540D\uFF1A");
		
		textName = new Text(container, SWT.BORDER);
		textName.setEditable(false);
		textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_1 = new Label(container, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_1.setText("\u4F53\u529B\u6D3B\u52A8\u6C34\u5E73\uFF1A");
		
		comboPal = new Combo(container, SWT.NONE);
		comboPal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		List<CustomerPal> pals=palService.getCustomerPalsByCustomerPalName(null);
		for(CustomerPal pal:pals){
			comboPal.add(pal.getName());
			comboPal.setData(pal.getName(), pal.getId());
		}
		//comboPal.setItems(customerService.getCustomerPals().toArray(new String[0]));
		Label label_2 = new Label(container, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_2.setText("\u8C03\u7406\u76EE\u6807\uFF1A");
		
		comboNurseTarget = new Combo(container, SWT.NONE);
		comboNurseTarget.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		List<NurseTarget> targets=this.nurseTargetService.getNurseTargetsByNurseTargetName(null);
		for(NurseTarget target:targets){
			comboNurseTarget.add(target.getName());
			comboNurseTarget.setData(target.getName(), target.getId());
		}
		
		Label lblNewLabel_1 = new Label(container, SWT.NONE);
		lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		lblNewLabel_1.setText("Effect");
		
		textEffect = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		GridData gd_textEffect = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
		gd_textEffect.heightHint = 79;
		textEffect.setLayoutData(gd_textEffect);
		//comboTarget.setItems(customerService.getCustomerNursedTargets().toArray(new String[0]));
		Label label_3 = new Label(container, SWT.NONE);
		label_3.setForeground(SWTResourceManager.getColor(0, 0, 0));
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_3.setText("\u5F00\u59CB\u65F6\u95F4\uFF1A");
		
		dateTimeBegin = new DateTime(container, SWT.BORDER | SWT.DROP_DOWN | SWT.LONG);
		
		Label label_4 = new Label(container, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_4.setText("\u9884\u8BA1\u7ED3\u675F\u65F6\u95F4\uFF1A");
		
		dateTimeForecastEnd = new DateTime(container, SWT.BORDER | SWT.DROP_DOWN | SWT.LONG);
		Calendar calendar=GregorianCalendar.getInstance();
		calendar.add(Calendar.DAY_OF_MONTH, 30);
		dateTimeForecastEnd.setDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
		
		Label lblNewLabel = new Label(container, SWT.NONE);
		lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		lblNewLabel.setText("备注：");
		
		textComment = new Text(container, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		textComment.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		this.textName.setText(name);
		//this.getShell().redraw();
	}
	@Override
	public IDialogSettings getDialogSettings() {
		// TODO Auto-generated method stub
		DialogSettings settings=new DialogSettings("settings");
		if(!comboPal.getText().trim().equals("")){
			settings.put("pal", comboPal.getData(comboPal.getText()).toString());
		}else{
			settings.put("pal", "");
		}
		if(!comboNurseTarget.getText().trim().equals("")){
			settings.put("target", comboNurseTarget.getData(comboNurseTarget.getText()).toString());
		}else{
			settings.put("target", "");
		}
		settings.put("effect", textEffect.getText());
		settings.put("starttime", dateTimeBegin.toString());
		settings.put("endtime", dateTimeForecastEnd.toString());
		settings.put("comment", textComment.getText());
		return settings;
	}
}
